class ModeMetaClass(type):
    def __new__(cls, name,bases,attrs):
        mappings=dict()
        for k,v in attrs.items():
            if isinstance(v,tuple):
                mappings[k]=v
        for k in mappings.keys():
            attrs.pop(k)

        attrs['__mappings__']=mappings
        attrs['__table__']=name
        return type.__new__(cls,name,bases,attrs)

class Model(object,metaclass=ModeMetaClass):
    def __init__(self,**kwargs):
        for k,v in kwargs.items():
            setattr(self,k,v)
            print(k,'=',v)
    def save(self):
        fields=[]
        args=[]
        for k,v in self.__mappings__.items():
            fields.append(v[0])
            args.append(getattr(self,k,None))
            print(k)
        args_temp=list()
        for temp in args:
            if isinstance(temp,int):
                args_temp.append(str(temp))
            elif isinstance(temp,str):
                args_temp.append("""'%s'"""%temp)
        sql = f'insert into {self.__table__}({",".join(fields)})  values ({",".join(args_temp)}))'
        print(f'SQL:{sql}')
class User(Model):
    uid=('uid','int unsigned')
    name=('username','varchar(30)')
    email=('email','varchar(30)')
    password=('password','varchar(30)')

class Guest(Model):
    uid=('uid','int unsigned')
    name=('username','varchar(30)')
    email=('email','varchar(30)')
    password=('password','varchar(30)')
    sex=('sex','char(1)')
u=User(uid=249746,name='AK',email='2497744746@qq.com',password='FW249746')
u.save()

g=Guest(uid=249746,name='AK',email='2497744746@qq.com',password='FW249746',sex='男')
g.save()